# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
import csv

from itemadapter import ItemAdapter


class AnjvkPipeline:

    def process_item(self, item, spider):
        props = item.get('props')

        header = []
        for x, y in props[0].items():
            header.append(str(x))

        body = []
        with open('anjvk.csv', 'a',encoding='utf-8') as f:
            f_csv = csv.writer(f)

            for x in props:
                one = []
                for y in header:
                    one.append(x.get(y))
                body.append(one)
            f_csv.writerows(body)
